//
//  YCHomeStatus.swift
//  weiBoSwift
//
//  Created by 刘胤辰 on 16/7/23.
//  Copyright © 2016年 it.com. All rights reserved.
//

import UIKit

class YCHomeStatus: NSObject {

     var id:Int64 = 0
     var text:String?
     var created_at:String?
     var source:String?
     var user:YCUser?
     //转发微博
     var retweeted_status:YCHomeStatus?
     //配图
     var pic_urls:[YCImageModel]?
    
    init(dict:[String : AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            //判断是否为nil，以及是否为字典
            guard let v=value as? [String : AnyObject] else{
                return
            }
            user=YCUser(dict: v)
        }else if key == "retweeted_status" {
            guard let v=value as? [String : AnyObject] else{
                return
            }
            retweeted_status=YCHomeStatus(dict: v)
        }else if key == "pic_urls" {
            
            //判断是否为nil并且是否可以转为字典数组
            guard let v=value as? [[String:AnyObject]] else{
                return
            }
            var tempArray:[YCImageModel]=[YCImageModel]()
            for dict in v {
                
                let image=YCImageModel(dict: dict)
                tempArray.append(image)
            }
            pic_urls=tempArray
            
        }else{
            
            //此处切记，是调用父类的方法
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
        
    }
}
